import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { AppModule } from './app.module';

const listenPort = 3000;
const logger = new Logger('main.ts');

/**
 * @description 主方法
 * @author maya
 * @date 2021-10-04
 */
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.enableCors();
  // app.enableCors({
  //   origin: /^http:\/\/127\.0\.0\.1:\d+/,
  //   optionsSuccessStatus: 200,
  // });

  const options = new DocumentBuilder()
    .setTitle('手机库存管理系统API')
    .setDescription('这是一个手机库存管理系统的接口文档')
    .setVersion('1.0')
    .addBearerAuth(
      {
        type: 'http',
        scheme: 'bearer',
        bearerFormat: 'JWT',
      },
      'jwt',
    )
    .build();

  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('api', app, document);

  logger.log(`listen in http://localhost:${listenPort}/api`);
  await app.listen(listenPort);
}
bootstrap();
